#include "Generate_C_std.h"
#include "Pattern_eval_expr_or_assign_var.h"

class Pattern_expr_builtin : public Pattern_eval_expr_or_assign_var
{
public:
	bool match(Statement* that)
	{
		bool result = Pattern_eval_expr_or_assign_var::match (that);
		if (not result)
			return false;

		return is_builtin_function (method_name->value->value);
	}

	Expr* rhs_pattern()
	{
		method_name = new Wildcard<METHOD_NAME>;
		arg = new Wildcard<Actual_parameter>;
		return new Method_invocation(
			NULL,
			method_name,
			new List<Actual_parameter*>(arg));
	}

	void generate_code (Generate_C* gen)
	{
		assert (!arg->is_ref);

		if (lhs)
		{
			assert (!agn->is_ref);
			INST (buf, "builtin_with_lhs",
					lhs->value, arg->value->rvalue,
					method_name->value->value, arg->value->get_filename ());
		}
		else
		{
			INST (buf, "builtin_no_lhs",
					arg->value->rvalue,
					method_name->value->value, arg->value->get_filename ());
		}
	}

protected:
	Wildcard<METHOD_NAME>* method_name;
	Wildcard<Actual_parameter>* arg;
};

CREATE(Pattern_expr_builtin)
